package cn.mst.vrs.util;

import cn.dev33.satoken.secure.SaSecureUtil;
import cn.mst.vrs.config.SecretProperties;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

@Component
public class CryptoUtil implements InitializingBean {
    @Resource
    private SecretProperties secretProperties;

    private static String privateKey;
    private static String publicKey;

    public static String encrypt(String original) {
        return SaSecureUtil.rsaEncryptByPublic(publicKey, original);
    }

    public static String decrypt(String encrypted) {
        return SaSecureUtil.rsaDecryptByPrivate(privateKey, encrypted);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        privateKey = secretProperties.getPrivateKey();
        publicKey = secretProperties.getPublicKey();
    }
}
